package com.sykj.cloud.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.sykj.cloud.common.log.enums.LogUserType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sykj.cloud.common.log.annotation.Log;

import com.sykj.cloud.common.security.annotation.PreAuthorize;
import com.sykj.cloud.system.domain.OrgSiteParameter;
import com.sykj.cloud.system.service.IOrgSiteParameterService;
import com.sykj.cloud.common.core.web.controller.BaseController;
import com.sykj.cloud.common.core.web.domain.AjaxResult;
import com.sykj.cloud.common.core.utils.poi.ExcelUtil;
import com.sykj.cloud.common.core.web.page.TableDataInfo;

/**
 * 站点参数表Controller
 *
 * @author mr.will
 * @date 2021-03-29
 */
@RestController
@RequestMapping("/site_parameter")
public class OrgSiteParameterController extends BaseController
{
    @Autowired
    private IOrgSiteParameterService orgSiteParameterService;

    /**
     * 新增站点参数表
     */
    @PreAuthorize(hasPermi = "system:site_parameter:add")
    @Log(title = "站点参数", logUserType = LogUserType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrgSiteParameter orgSiteParameter)
    {
        int i=orgSiteParameterService.insertOrgSiteParameter(orgSiteParameter);
        if(i==-1){
            return AjaxResult.error("该站点参数code已经存在，不能再次新增");
        }
        return toAjax(i);
    }

    /**
     * 修改站点参数表
     */
    @PreAuthorize(hasPermi = "system:site_parameter:edit")
    @Log(title = "站点参数", logUserType = LogUserType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrgSiteParameter orgSiteParameter)
    {
        return toAjax(orgSiteParameterService.updateOrgSiteParameter(orgSiteParameter));
    }

    /**
     * 删除站点参数表
     */
    @PreAuthorize(hasPermi = "system:site_parameter:remove")
    @Log(title = "站点参数", logUserType = LogUserType.DELETE)
    @DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(orgSiteParameterService.deleteOrgSiteParameterByIds(guids));
    }

    /**
     * 获取站点参数表详细信息
     */
    @PreAuthorize(hasPermi = "system:site_parameter:query")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(orgSiteParameterService.getOrgSiteParameterById(guid));
    }

    /**
     * 导出站点参数表列表
     */
    @PreAuthorize(hasPermi = "system:site_parameter:export")
    @Log(title = "站点参数", logUserType = LogUserType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrgSiteParameter orgSiteParameter) throws IOException
    {
        List<OrgSiteParameter> list = orgSiteParameterService.listOrgSiteParameters(orgSiteParameter);
        ExcelUtil<OrgSiteParameter> util = new ExcelUtil<OrgSiteParameter>(OrgSiteParameter.class);
        util.exportExcel(response, list, "site_parameter");
    }

    /**
     * 查询站点参数表列表
     */
    @PreAuthorize(hasPermi = "system:site_parameter:list")
    @GetMapping("/list")
    public TableDataInfo list(OrgSiteParameter orgSiteParameter)
    {
        startPage();
        List<OrgSiteParameter> list = orgSiteParameterService.listOrgSiteParameters(orgSiteParameter);
        return getDataTable(list);
    }
}
